package com.ww.utils;

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.digest.DigestUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class ZhiyoubaoIntefaceUtils {
	
	final static String APP_CODE = "2016081700000041";
	final static String APP_KEY = "6be60b38471e4c049848a91e5f612b14";
	final static String REQUEST_URL = "http://test1.sendinfo.com.cn/zybdata/prodata/getSpotsSaleInfo.htm";
	
	
	public static void main(String[] args) throws UnsupportedEncodingException, URISyntaxException {
		
		Map<String, String> param = new HashMap<>();
		param.put("beginTime", "2015-09-01 00:00:00");
		param.put("endTime", "2015-09-05 00:00:00");
		param.put("groupCode", "LR9bmhLZIt");
		param.put("parkCode", "001");
		
		param = MapUtils.sortMapByKey(param);
		String paramUrl = MapUtils.parseToStr(param);
		paramUrl = paramUrl.replaceFirst("&", "");
		System.out.println(paramUrl);
		
		String sign = DigestUtils.md5Hex((paramUrl + APP_KEY).getBytes(Charset.forName("UTF-8")));
		System.out.println(sign);
		
		param.put("appCode", APP_CODE);
		param.put("sign", sign);
		
		JSONObject paramJson = JSONObject.parseObject(JSON.toJSONString(param));
		
		Map<String, Object> postParam = new HashMap<>();
		postParam.put("req_data", paramJson.toJSONString());
		String rs = HttpClientUtils.httpPostRequest(REQUEST_URL, postParam);
		System.out.println(rs);
		
	}
	
}
